home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / StarsDemo / Stars.bb < prev   
Encoding:
Text File  |  2002-04-10  |  2.4 KB  |  58 lines

  1. ; Star Demo by Dave Kirk (GFK)
  2. ;
  3. ; Demonstrates use of 'types', AnimImages, functions, reading the mouse position and double buffering
  4. ;
  5. ; Change the value in NewStars to change the number of new stars generated each frame
  6. ; On my AMD-900 I can set it to 75 and get over 6,000 stars on screen without losing a frame!
  7.  
  8. AppTitle "Star Demo"
  9.  
  10.  
  11. Graphics 800,600,16,1                                    ; Set graphics mode to 800x600 res, 16 bit, force full screen even in debug mode.
  12. SetBuffer BackBuffer()                                    ; Ready for double-buffering
  13. Global Star = LoadAnimImage("MouseStars.bmp",9,9,0,8)     ; Load star images
  14. Global Count = 0                                        ; simple counter to keep track of the number of stars on screen
  15.  
  16. Global NewStars = 20                                    ; PLAY WITH THIS VALUE FOR MORE/LESS STARS
  17. Global FPS = 50                                            ; Maximum frames per second
  18.  
  19. While KeyDown(1) = 0                                    ; Continue until the ESCAPE key is pressed
  20.     t = MilliSecs()        
  21.     Cls
  22.     Text 0,0,"Hold down left mouse button to generate stars!"
  23.     Text 0,12,"Number of stars on screen: " + Count
  24.     MouseParticles                                        ; Call the function which updates existing stars and adds new ones
  25.     While MilliSecs()-t < 1000/FPS : Wend
  26.     Flip                                                ; Switch the backbuffer and frontbuffer over (double-buffering)
  27. Wend
  28.  
  29. End                                                        ; End the program (when ESCAPE is pressed)
  30.  
  31.  
  32. Function MouseParticles()
  33.     If MouseDown(1)                                        ; If left mouse button pressed, add new stars!
  34.         For N = 1 To NewStars
  35.             P.MousePart = New MousePart                    ; Create a new star
  36.             P\X = MouseX()                                ; Set horizontal position to same as mousex
  37.             P\Y = MouseY()                                ; Set vertical position to same as mousey
  38.             P\XS = Rnd(-5.0,5.0)                        ; Random horizontal speed
  39.             P\YS = Rnd(-5.0,5.0)                        ; Random vertical speed
  40.             P\image = Rand(0,7)                            ; Random start frame for star animation
  41.         Next
  42.     EndIf
  43.     count = 0
  44.     For P.MousePart = Each MousePart                    ; Update existing stars!
  45.         count = count + 1                                ; Count the number of stars on screen
  46.         P\YS = P\YS + 0.25                                ; Increase vertical speed
  47.         P\X = P\X + P\XS                                ; Update horizontal position
  48.         P\Y = P\Y + P\YS                                ; update vertical position
  49.         P\Image = P\Image + 1                            ; Animate the star thru frames 0-7
  50.         If P\Image = 8 Then P\Image = 0
  51.         DrawImage Star,P\X,P\Y,P\Image                    ; Draw a star
  52.         If P\Y > 800 Then Delete P                        ; Delete a star if it drops off the bottom of the screen!
  53.     Next
  54. End Function
  55.  
  56. Type MousePart
  57.     Field X#,Y#,XS#,YS#,Image#
  58. End Type